package com.cdsf;

//特别注意，下面的是 tk.MapperScan

import com.cdsf.basicmanage.api.BasicmanageService;
import com.cdsf.webservice.NetWebService;
import com.spring4all.swagger.EnableSwagger2Doc;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.ws.config.annotation.EnableWs;
import tk.mybatis.spring.annotation.MapperScan;

import javax.xml.ws.Endpoint;
import java.net.URL;

/**
 * @author kennedy
 * @since 2015-12-12 18:22
 */
@Controller
@SpringBootApplication
@EnableSwagger2Doc
@EnableWs
@EnableDiscoveryClient
@MapperScan(basePackages = "com.cdsf.kennedy.*.mapper")
public class Application implements CommandLineRunner {
    private Logger logger = LoggerFactory.getLogger(Application.class);
    @Autowired
    private Bus bus;
    @Autowired
    private NetWebService netWebService;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        // 项目启动后动作
        logger.info("服务启动完成!");
    }

    @RequestMapping("/add")
    String home() {
        return "redirect:user/add";
    }

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, netWebService);
        endpoint.publish("/Hello");
        return endpoint;
    }

    @Bean
    public JaxWsPortProxyFactoryBean jaxWsPortProxyFactoryBean() throws Exception {
        JaxWsPortProxyFactoryBean proxy = new JaxWsPortProxyFactoryBean();
        proxy.setWsdlDocumentUrl(new URL("http://10.0.8.54:58088/bms/public/ws/BasicWebService?wsdl"));
        proxy.setServiceName("BasicmanageServiceService");
        proxy.setPortName("BasicmanageServicePort");
        proxy.setServiceInterface(BasicmanageService.class);
        proxy.setNamespaceUri("http://api.basicmanage.cdsf.com/");
        proxy.afterPropertiesSet();
        return proxy;
    }
}
